# import json
# import time
#
# from selenium import webdriver
# from selenium.webdriver import Edge
# from selenium.webdriver import EdgeOptions
# from selenium.common.exceptions import WebDriverException
#
# #
# # mobile_emulation = {"deviceName": "iPhone XR"}
# # options = Options()
# # options.add_argument("--auto-open-devtools-for-tabs")
# # options.add_experimental_option("mobileEmulation", mobile_emulation)
# # webdriver = webdriver.Edge(options)
# #
# # webdriver.get('https://daojia.jd.com/html/index/index.html?sid_for_share=99125_3')
# #
# # time.sleep(123455)
#
# caps = {
#     # "browserName": "edge",
#     # 'goog:loggingPrefs': {'performance': 'ALL'}  # 开启日志性能监听
# }
#
# # 将caps添加到options中
# # for key, value in caps.items():
# #     options.set_capability(key, value)
#
#
# # mobile_emulation = {"deviceName": "iPhone XR"}
# # options.add_experimental_option("mobileEmulation", mobile_emulation)
# # 启动浏览器
# edge_options = EdgeOptions()
# # mobile_emulation = {"deviceName": "iPhone XR"}
# # edge_options.add_experimental_option("mobileEmulation", mobile_emulation)
# edge_options.set_capability("ms:loggingPrefs", {'performance': 'ALL'})
# driver = Edge(edge_options)
# driver.get('https://daojia.jd.com/html/index/index.html?sid_for_share=99125_3')
#
# time.sleep(10000)
#
# def filter_type(_type: str):
#     types = [
#         'application/javascript', 'application/x-javascript', 'text/css', 'webp', 'image/png', 'image/gif',
#         'image/jpeg', 'image/x-icon', 'application/octet-stream'
#     ]
#     if _type not in types:
#         return True
#     return False
#
#
# performance_log = driver.get_log("performance")
# for packet in performance_log:
#     message = json.loads(packet.get('message')).get('message')  # 获取message的数据
#     if message.get('method') != 'Network.responseReceived':  # 如果method 不是 responseReceived 类型就不往下执行
#         continue
#     packet_type = message.get('params').get('response').get('mimeType')  # 获取该请求返回的type
#     if not filter_type(_type=packet_type):  # 过滤type
#         continue
#     requestId = message.get('params').get('requestId')  # 唯一的请求标识符。相当于该请求的身份证
#     url = message.get('params').get('response').get('url')  # 获取 该请求  url
#     try:
#         resp = driver.execute_cdp_cmd('Network.getResponseBody', {'requestId': requestId})  # selenium调用 cdp
#         print(f'type: {packet_type} url: {url}')
#         print(f'response: {resp}')
#         print()
#     except WebDriverException:  # 忽略异常
#         pass

import hashlib
import hmac
from datetime import datetime

import requests
import time
import base64


def sha256_encode(body):
    '''
    :body转化为256:
    :return:
    '''
    # 将参数转换为bytes类型
    data_bytes = bytes(body, 'utf-8')
    # 创建SHA256加密对象
    sha256_obj = hashlib.sha256(data_bytes)
    # 获取SHA256加密结果的十六进制表示
    sha256_hex = sha256_obj.hexdigest()
    return sha256_hex

def getTimestamp():
    t = int(datetime.now().timestamp() * 1000)
    timestamp = t / 1000.0  # 将时间戳除以1000，转换为秒
    dt = datetime.fromtimestamp(timestamp)
    st1 = dt.strftime('%Y%m%d%H%M%S%f')[:-3]  # 格式化日期字符串，去掉最后三位微秒数
    print(st1)

getTimestamp()